package com.zhangyu.eat.me.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhangyu.eat.R;
import com.zhangyu.eat.base.GlideRoundTransform;
import com.zhangyu.eat.base.bean.HotBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by SoSho on 2016/10/21.
 */

public class HotAdapter extends BaseAdapter {
    List<HotBean.ListBean.LivelistBean> mList = new ArrayList<>();

    public void setData(List<HotBean.ListBean.LivelistBean> list) {
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        return mList.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.hot_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(parent.getContext()).load(mList.get(position).getUser().getAvatar()).transform(new GlideRoundTransform(parent.getContext(),40)).into(holder.itemLimage);
        Glide.with(parent.getContext()).load(mList.get(position).getCover()).into(holder.itemBimage);
        holder.itemTitle.setText(mList.get(position).getUser().getNickname());
        holder.itemSubtitle.setText(mList.get(position).getUser().getCity());
        holder.itemNum.setText(String.valueOf(mList.get(position).getUser().getCredits()));
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.item_limage)
        ImageView itemLimage;
        @BindView(R.id.item_title)
        TextView itemTitle;
        @BindView(R.id.item_subtitle)
        TextView itemSubtitle;
        @BindView(R.id.item_num)
        TextView itemNum;
        @BindView(R.id.item_bimage)
        ImageView itemBimage;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
